if ((typeof LOGINZA == "undefined") || !LOGINZA) {
	// РёРЅРёС†РёР°Р»РёР·Р°С†РёСЏ РѕР±СЉРµРєС‚Р° LOGINZA
    var LOGINZA = {
    	'loaded': false,
        'token_url': null,
        'selected_provider': null,
        'providers_set': null,
        'service_host': 'https://loginza.ru',
        'lang': null
    };
}
// РїРѕРєР°Р·Р°С‚СЊ С„РѕСЂРјСѓ
LOGINZA.show = function () {
	// РїСЂРµРґ РІС‹Р±РѕСЂ РїСЂРѕРІР°Р№РґРµСЂР°
	LOGINZA.selected_provider = LOGINZA.getQueryStringValue(this, 'provider');
	// РЅР°Р±РѕСЂ РїСЂРѕРІР°Р№РґРµСЂРѕРІ РІ РІРёРґР¶РµС‚Рµ
	LOGINZA.providers_set = LOGINZA.getQueryStringValue(this, 'providers_set');
	// РїРѕР»СѓС‡РµРЅРёРµ token
	LOGINZA.token_url = LOGINZA.getQueryStringValue(this, 'token_url');
	// СѓСЃС‚Р°РЅРѕРІРєР° СЏР·С‹РєР° РёРЅС‚РµСЂС„РµР№СЃР°
	LOGINZA.lang = LOGINZA.getQueryStringValue(this, 'lang');
	
	if (!LOGINZA.loaded) {
		var cldDiv = document.createElement("div");
		cldDiv.setAttribute('id', 'loginza_auth_form');
		cldDiv.setAttribute('style', 'overflow: visible; z-index: 10000; background-color: transparent; position: fixed; top: 0px; display: block; text-align: center; left: 0px; height: 878px; width: 1247px; padding-top: 125px; background-image: url('+LOGINZA.service_host+'/img/widget/overlay.png);');
		cldDiv.innerHTML = '<div style="position:relative;display:inline;overflow:visible;"><img style="position:relative;left:348px;top:-332px;cursor:hand;" onclick="LOGINZA.close();" src="'+
			LOGINZA.service_host+'/img/widget/close.gif" width="7" height="7" alt="X" border="0"/></div>'+
			'<iframe id="loginza_main_ifr" width="359" height="350" scrolling="no" frameborder="0" src="javascript:\'<html><body style=background-color:transparent><h1>Loading...</h1></body></html>\'"></iframe>';
		try {
			cldDiv.style.paddingTop = (window.innerHeight-350)/2 + 'px';
		} catch (e) {
			cldDiv.style.paddingTop = '100px';
		}
		cldDiv.style.paddingLeft = 0;
		cldDiv.style.height = '2000px';
		cldDiv.style.width = document.body.clientWidth + 50 + 'px';
		// СЃРѕР·РґР°РЅРёРµ РєРѕРЅС‚РµР№РЅРµСЂР° РґР»СЏ С„РѕСЂРјС‹
		document.body.appendChild(cldDiv);
		// С„РѕСЂРјР° Р·Р°РіСЂСѓР¶РµРЅР°
		LOGINZA.loaded = true;
	}
	if (!LOGINZA.token_url) {
		alert('Error token_url value!');
	} else {
		// Р·Р°РіСЂСѓР·РєР° С„РѕСЂРјС‹
		document.getElementById('loginza_main_ifr').setAttribute('src', LOGINZA.service_host+'/api/widget.php?overlay=true&w='+document.body.clientWidth+'&token_url='+encodeURIComponent(LOGINZA.token_url)+'&provider='+encodeURIComponent(LOGINZA.selected_provider)+'&providers_set='+encodeURIComponent(LOGINZA.providers_set)+'&lang='+encodeURIComponent(LOGINZA.lang));
	}
	// РїРѕРєР°Р·Р°С‚СЊ С„РѕСЂРјСѓ
	document.getElementById('loginza_auth_form').style.display = '';
	return false;
}
LOGINZA.close = function () {
	document.getElementById('loginza_auth_form').style.display = 'none';
}
// РёР·РјРµРЅРµРЅРёРµ СЂР°Р·РјРµСЂРѕРІ РѕРєРЅР° Р±СЂР°СѓР·РµСЂР°
LOGINZA.resize = function () {
	var frm = document.getElementById('loginza_auth_form');
	if (frm) {
		frm.style.width = document.body.clientWidth + 50 + 'px';
		try {
			frm.style.paddingTop = (window.innerHeight-350)/2 + 'px';
		} catch (e) {
			frm.style.paddingTop = '100px';
		}
	}
}
// РїРѕР»СѓС‡РµРЅРёРµ РїР°СЂР°РјРµС‚СЂР° РёР· СЃСЃС‹Р»РєРё
LOGINZA.getQueryStringValue = function (link, key) {
	var url_str = link.href;
    var match = null;
    var query_str = url_str.match(/^[^?]*(?:\?([^#]*))?(?:$|#.*$)/)[1]
    var _query_regex = new RegExp("([^=]+)=([^&]*)&?", "g");
    while ((match = _query_regex.exec(query_str)) != null)
    {
        if (decodeURIComponent(match[1]) == key) {
            return decodeURIComponent(match[2]);
        }
    }
    return null;
}
LOGINZA.findClass = function (str, node) {
	if(document.getElementsByClassName) return (node || document).getElementsByClassName(str);
	else {
		var node = node || document, list = node.getElementsByTagName('*'), length = list.length, Class = str.split(/\s+/), classes = Class.length, array = [], i, j, key;
		for(i = 0; i < length; i++) {
			key = true;
			for(j = 0; j < classes; j++) if(list[i].className.search('\\b' + Class[j] + '\\b') == -1) key = false;
			if(key) array.push(list[i]);
		}
		return array;
	}
}
LOGINZA.addEvent = function (obj, type, fn){
	if (obj.addEventListener){
	      obj.addEventListener( type, fn, false);
	} else if(obj.attachEvent) {
	      obj.attachEvent( "on"+type, fn );
	} else {
	      obj["on"+type] = fn;
	}
}
LOGINZA.init = function () {
	// РѕР±СЂР°Р±РѕС‚С‡РёРє РЅР° РѕС‚РєСЂС‹С‚РёРµ С„РѕСЂРјС‹
	if (document.getElementById('loginza')) {
		document.getElementById('loginza').onclick = LOGINZA.show;
	}
	var i, list = LOGINZA.findClass('loginza'), length = list.length;
	for(i = 0; i < length; i++) list[i].onclick = LOGINZA.show;
	// РїСЂРѕС‡РёРµ РѕР±СЂР°Р±РѕС‚С‡РёРєРё
	LOGINZA.addEvent(window, 'resize', LOGINZA.resize);
	LOGINZA.addEvent(document, 'keydown', function(e) {
		e = e || window.event;
		if (e.keyCode == 27) {
			LOGINZA.close();
		}
		return true;
	});
}
LOGINZA.addEvent(window, 'load', LOGINZA.init);